//package com.example.villagedevelop.generator.config;
//
//import com.example.villagedevelop.generator.service.impl.MyUserDetailServiceImpl;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//@Configuration
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//    @Autowired
//    private MyUserDetailServiceImpl myUserDetailService;
//
//    /**
//      授权规则
//     */
//    @Override
//    protected void configure(HttpSecurity httpSecurity) throws Exception {
//        //定制请求的授权规则
//        //角色的设置需要和上面的权限一致，不然会报403
////        httpSecurity.authorizeRequests().antMatchers("/generator/**").hasRole("ADMIN");
//        //开启自动配置的登录功能
//        httpSecurity.formLogin()
//                .loginPage("/login.html")
//                .loginProcessingUrl("/authentication/form")
//                .defaultSuccessUrl("/case/case0",true).permitAll() //登陆成功之后跳转的路径
//                .and()
//                .authorizeRequests()    //对请求授权
//                .antMatchers("/login.html","/authentication/form").permitAll()    //这些页面不需要身份验证
//                .antMatchers("/test/index").hasAuthority("ROLE_ADMIN")
//                .anyRequest()   //任何请求
//                .authenticated()    //都需要身份认证
//                .and().csrf().disable();
//    }
//
//    /**
//    认证规则
//   */
//    @Bean
//    PasswordEncoder passwordEncoder(){
//        return new BCryptPasswordEncoder();
//    }
//
//    //在这里完成获得数据库中的用户信息
//    //密码一定要加密
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        auth.userDetailsService(myUserDetailService).passwordEncoder(new BCryptPasswordEncoder());
//    }
//
//}
